package io;

import org.junit.jupiter.api.Test;

import java.io.*;

/**
 * @description: io流
 * @author: rock
 * @create:
 **/
public class Io {
    public static void main(String[] args) {
        test1();
    }



    private  static void test1(){
        String s1 = "D:/demo/lalala.txt";
        String s2 = "D:/demo/lalala-s.txt";
        try(            InputStreamReader inputStreamReader=
                                new InputStreamReader(new FileInputStream(s1),"UTF-8");
                        OutputStreamWriter outputStreamWriter =
                                new OutputStreamWriter(new FileOutputStream(s2,true),"UTF-8");) {




            //读取文件内容
            char[] chars = new char[1024];
            int len = -1;
            System.out.println("读取的内容：");
            do {
                len = inputStreamReader.read(chars, 0, 1024);
                if (len<0){
                    System.out.println("文件为空！");
                }
                if(len>0){
                    String str = new String(chars,0,len);
                    System.out.println(str);
                    outputStreamWriter.write(chars,0,len);



                }

            } while (len > 0);
            //清空和刷新写出缓存去
            inputStreamReader.close();
            outputStreamWriter.close();



        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
